package com.example.newsSys.listener;

import com.example.newsSys.constants.ListenerConstants;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
@Slf4j
public class OnlineHttpServletContextListener implements ServletContextListener {
    // 监听ServletContext对象创建 创建时初始化一个存放在线用户的集合
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.info("ServletContext对象创建");
        ServletContext context = sce.getServletContext();
        ArrayList<String> onlineList = new ArrayList<>();
        context.setAttribute(ListenerConstants.ONLINE_LIST,onlineList);
    }
}
